package br.com.rumus.dao.cadastro;

import java.util.List;

import javax.persistence.Query;

import br.com.rumus.dao.DAOGenerico;
import br.com.rumus.dominio.cadastro.UF;

public class UFDAO extends DAOGenerico<UF, Long> {
	
	@SuppressWarnings("unchecked")
	public List<UF> pesquisar( UF uf, int registro, int quantidade ){
		Query query = getEntityManager().createNamedQuery("JPQL_LISTAR_UF");
		query.setParameter("nome",(uf!=null&&uf.getNome()!=null&&!uf.getNome().equals(""))?uf.getNome():null);
		query.setParameter("sigla",(uf!=null&&uf.getSigla()!=null&&!uf.getSigla().equals(""))?uf.getSigla():null);
		query.setParameter("codigoIBGE",(uf!=null&&uf.getCodigoIBGE()!=null?uf.getCodigoIBGE():null));
		query.setFirstResult(registro);
		query.setMaxResults(quantidade);
		return query.getResultList();
	}

	public int pesquisar( UF uf ){
		Query query = getEntityManager().createNamedQuery("JPQL_CONTAR_UF");
		query.setParameter("nome",(uf!=null&&uf.getNome()!=null&&!uf.getNome().equals(""))?uf.getNome():null);
		query.setParameter("sigla",(uf!=null&&uf.getSigla()!=null&&!uf.getSigla().equals(""))?uf.getSigla():null);
		query.setParameter("codigoIBGE",(uf!=null&&uf.getCodigoIBGE()!=null?uf.getCodigoIBGE():null));
        Number registros = null;
        registros = (Number) query.getSingleResult();
        return registros == null ? 0 : registros.intValue();
	}

}